<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	//系统首页
    public function index(){

        $category = D('Category')->getTree();
        $lists    = D('Document')->lists(null);

        $this->assign('category',$category);//栏目
        $this->assign('lists',$lists);//列表
        $this->assign('page',D('Document')->page);//分页                 
        $this->display();
    }

    //产品1   CP1控制器
    public function cp1(){
        $category = D('Category')->where('pid = 65')->select();
        //var_dump($category);
        $img = $desc = $canshu = $fuwu= $faq= '';
        foreach ($category as $key => $value) {
            $id = $value['id'];
            $title = $value['title'];
            $map = array();
            $map['category_id'] = $id;
            //var_dump($value);

            $con = D('Document')->where($map)->select();
            
            $rand_key = array_rand($con,1);
            $rand_val = $con[$rand_key];
            $rand_id = $rand_val['id'];

            $wh = array();
            $wh['id'] = $rand_id;
            $rand_con = D('DocumentArticle')->where($wh)->find();
            $content = $rand_con['content'];

            if('简介' == $title){
                $desc = $content;
            }else if('图片' == $title){
                $img = $content;
            }else if('参数' == $title){
                $canshu = $content;
            }else if('服务支持' == $title){
                $fuwu = $content;
            }else{
                $faq = $content;
            }
        }

        $this->assign('desc',$desc);
        $this->assign('img',$img);
        $this->assign('canshu',$canshu);
        $this->assign('fuwu',$fuwu);
        $this->assign('faq',$faq);
        $this->display();
    }

    //产品2  CP2控制器
    public function cp2(){
        //$category = D('Category')->where('pid = 66')->select();  改pid即可
    }

}